/// Created by Nazariy Jaworski Copyright (c) 2013
/// Bot program
///
/// main.cpp - use it to run main class object
///
/// To Do list:
///  - ...
///
/// v 0.1        02.04.2013

#include "globalargs.h"

#include "bot.h"
#include "botui.h"
#include "logger.h"
#include <conio.h>

#include "TESTS/test_node.h"
#include "TESTS/test_element.h"
#include "TESTS/test_tree.h"
#include "TESTS/test_matrix.h"

#include "CLKERNEL/openclmanager.h"

//#include "botwtui.h"

int main(int argc, char** argv)
{
    __argc = argc;
    __argv = argv;

    Bot::GetInstance()->Init();
    BotUI::GetInstance();
    Logger myLogger("botLog.txt");
    OpenCLManager::getInstance();

    BotUI::GetInstance().connect(&BotUI::GetInstance(), SIGNAL(SIGNAL_Exit()),
        Bot::GetInstance(), SLOT(quit()));
    BotUI::GetInstance().connect(&BotUI::GetInstance(), SIGNAL(SIGNAL_FatalError(QString)),
        Bot::GetInstance(), SLOT(SLOT_FatalError(QString)));
    BotUI::GetInstance().connect(&BotUI::GetInstance(), SIGNAL(SIGNAL_RegisterAtEnvironment()),
        Bot::GetInstance()->myCommunicator,SLOT(RegisterAtEnvironment()));
    BotUI::GetInstance().connect(&BotUI::GetInstance(), SIGNAL(SIGNAL_ShowClients()),
        Bot::GetInstance()->myCommunicator,SLOT(ShowClients()));
    BotUI::GetInstance().connect(&BotUI::GetInstance(), SIGNAL(SIGNAL_ShowOCLPlatforms()),
        &OpenCLManager::getInstance(),SLOT(SLOT_ShowPlatformsInfo()));
    BotUI::GetInstance().connect(&BotUI::GetInstance(), SIGNAL(SIGNAL_ShowOCLDevices()),
        &OpenCLManager::getInstance(),SLOT(SLOT_ShowDevicesInfo()));

    Bot::GetInstance()->connect(Bot::GetInstance(), SIGNAL(SIGNAL_WriteUIString(QString)),
        &BotUI::GetInstance(), SLOT(SLOT_WriteUIString(QString)));
    Bot::GetInstance()->connect(Bot::GetInstance(), SIGNAL(SIGNAL_WriteToLog(QString)),
        &myLogger, SLOT(SLOT_WriteToLog(QString)));

    OpenCLManager::getInstance().connect(&OpenCLManager::getInstance(), SIGNAL(SIGNAL_WriteUIString(QString)),
        &BotUI::GetInstance(), SLOT(SLOT_WriteUIString(QString)));
    OpenCLManager::getInstance().connect(&OpenCLManager::getInstance(), SIGNAL(SIGNAL_WriteToLog(QString)),
        &myLogger, SLOT(SLOT_WriteToLog(QString)));

    myLogger.connect(&myLogger, SIGNAL(SIGNAL_WriteUIString(QString)),
        &BotUI::GetInstance(), SLOT(SLOT_WriteUIString(QString)));
    myLogger.connect(&myLogger, SIGNAL(SIGNAL_FatalError(QString)),
        Bot::GetInstance(), SLOT(SLOT_FatalError(QString)));

    BotUI::GetInstance().start();
    if(Bot::GetInstance()->isOk && BotUI::GetInstance().isOk && myLogger.isOk)
        Bot::GetInstance()->exec();
    else
    {
        if(!Bot::GetInstance()->isOk)
            std::cout << "FATAL ERROR: Bot is not startet\n";
        else if(!BotUI::GetInstance().isOk)
                std::cout << "FATAL ERROR: UI is not startet\n";
        else if(!myLogger.isOk)
                std::cout << "FATAL ERROR: Logger is not startet\n";
    }

    /*nodeTest1();
    nodeTest2();
    nodeTest3();

    elementTest1();

    treeTest1();

    matrixTest1();
    matrixTest2();
    matrixTest3();
    matrixTestSpeedComparison();*/

    return 0;
}

